<?php


namespace App\Transformers\Member;


use App\Models\OtherOrder;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class OtherOrderTransFormer extends TransformerAbstract
{
    protected $availableIncludes = ['user'];


    public function transform(OtherOrder $otherOrder )
    {


        return [
            'id' => $otherOrder->id,
            'user_id' => $otherOrder->user_id ?? '',
            'order_id' => $otherOrder->order_id ?? '',
            'code' => $otherOrder->code ?? '',
            'type' =>$otherOrder->typeEnum[$otherOrder->type]  ?? '',
            'member_type' => $otherOrder->typeEnum[$otherOrder->member_type] ?? '',
            'pay_type' => $otherOrder->typeEnum[$otherOrder->pay_type]  ?? '',
            'paid' => $otherOrder->paid ?? '',
            'pay_price' => $otherOrder->pay_price ?? '',
            'trade_no' => $otherOrder->trade_no ?? '',
            'channel_type' => $otherOrder->typeEnum[$otherOrder->channel_type]  ?? '',
            'member_price' => $otherOrder->member_price ?? '',
            'pay_time' => $otherOrder->pay_time ?? '',
            'is_free' => $otherOrder->is_free ?? '',
            'is_permanent' => $otherOrder->is_permanent ?? '',
            'overdue_time' => $otherOrder->overdue_time ?? '',
            'vip_day' => $otherOrder->vip_day ?? '',
            'created_at' => $otherOrder->created_at ? $otherOrder->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $otherOrder->updated_at ? $otherOrder->updated_at->format("Y-m-d H:i:s") : '',
        ];

    }

    /**
     * 额外的用户信息
     */
    public function includeUser(OtherOrder $otherOrder)
    {
        return $this->item($otherOrder->user, new UserTransformer());
    }
}
